﻿using System.Collections.Generic;
using Red.Core;

namespace Red.Controls.Depot.FileViewItemsProviders
{
    public class AssetsItemsProvider : FileViewItemsProvider
    {
        private readonly List<string> _subFolders;

        public override bool ShowGroups { get { return true; } }

        public override bool ReEnumerateOnSelection { get { return true; } }

        public AssetsItemsProvider( string path, DepotInfo depot, List<string> subFolders ) 
            : base( path, depot )
        {
            _subFolders = subFolders;
        }

        public override void EnumerateItems( IList<FolderInfo> folders, IList<FileInfo> files, IList<FileInfo> selectedFilesPaths )
        {
            // it's just making up dummy data, the real logic may be completely different
            if ( _subFolders.Count > 0 )
            {
                // ok, we got some folders, so it's still 'folders' level
                foreach ( string folder in _subFolders )
                { // IsFake set to true means that the folder doesn't correspond to any real on-disk folder
                    folders.Add( new FolderInfo { Name = folder, IsFake = true } );
                }
            }
            else
            {
                // no folder we're on the 'asset' level, so put some dummy 'asset-like' stuff
                // paths are meant to be real, absolute paths to resources

                files.Add( new FileInfo {
                    FullPath = Depot.GetAbsolutePath( @"editor\quercus.xbm" ), Group = "Files",
                    FullThumbnailPath = Depot.GetAbsolutePath( @"qa\users\lw\Thumbs\Kitty.gif" ),
                    Description = "That's a long description with several lines\n\nType: blah\nNumber of thingies: a lot\nThingamabobs included: 42"
                } );
                files.Add( new FileInfo {
                    FullPath = Depot.GetAbsolutePath( @"editor\quercus_big.w2mesh" ), Group = "Files",
                    FullThumbnailPath = Depot.GetAbsolutePath( @"qa\users\lw\Thumbs\Peacock.jpg" ),
                } );
                files.Add( new FileInfo {
                    FullPath = Depot.GetAbsolutePath( @"editor\quercus_n.xbm" ), Group = "Files",
                    FullThumbnailPath = Depot.GetAbsolutePath( @"qa\users\lw\Thumbs\Witcher.jpg" ),
                } );
                files.Add( new FileInfo
                {
                    FullPath = Depot.GetAbsolutePath( @"editor\querqus_cap_deform_n.xbm" ), Group = "Files",
                    FullThumbnailPath = Depot.GetAbsolutePath( @"qa\users\lw\Thumbs\Non_existent_image.jpg" ),
                } );

                // this is an example of listing dynamic dependencies basing on selected item
                foreach ( FileInfo selectedFile in selectedFilesPaths )
                {
                    if ( selectedFile.Group == "Files" )
                    {
                        string fileName = System.IO.Path.GetFileName( selectedFile.FullPath );
                        files.Add( new FileInfo {
                            FullPath = Depot.GetAbsolutePath( fileName + ".first.dependency" ), Group = "Dependency", IsDisabled = true
                        } );
                        files.Add( new FileInfo {
                            FullPath = Depot.GetAbsolutePath( fileName + ".second.dependency" ), Group = "Dependency", IsDisabled = true
                        } );
                        files.Add( new FileInfo {
                            FullPath = Depot.GetAbsolutePath( fileName + ".third.dependency" ), Group = "Dependency", IsDisabled = true
                        } );
                    }
                }
            }
        }
    }
}
